package com.easyapi.server.observation;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.easyapi.server.config.RabbitmqConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
* @author: javadadi
* @Time: 14:23
* @ClassName: DatasourceObserver
*/
@Component
public class DatasourceObserver implements Observer {
    @Resource
    private RabbitTemplate rabbitTemplate;

    @Override
    public void update(String action, Long id) {
        JSONObject jsonObject = JSONUtil.createObj().put("action", action).put("id", id);
        String json = jsonObject.toString();
        rabbitTemplate.convertAndSend(RabbitmqConfig.DIRECT_EXCHANGE,RabbitmqConfig.DATASOURCE_ROUTING_KEY,json);
    }
}
